// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/iot/api/IotNodeApiApi'

import OneClass from '@api/iot/model/NodeQueryReq'

const SubmitClass = OneClass

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne(one) {
    return one.id
  },
  async getOne(one, TIP = '查询单项') {
    const DTO = CORE.grpcDTO(OneClass, { id: one.id, page: 1, pageSize: 1 })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryNodeList', DTO)
    return (resp.data || [])[0] || one
  },
  transOne(obj) {
    return obj
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit({ id }, TIP = '提交') {
    const DTO = CORE.grpcDTO(SubmitClass, { id })
    await CORE.grpc(TIP, CLIENT, 'nodeHealth', DTO)
    return CORE.grpcOK(TIP)
  },
}
